package priv.pront.code.robot.roboCom_pri_2021.zhi.fu;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

/**
 * @Description:
 * @Author: pront
 * @Time:2023-07-13 15:07
 */
public class 机器人拼图 {

    static int[] dx = {0, 1, 0, -1}, dy = {1, 0, -1, 0};
    static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter out = new PrintWriter(System.out);
    static int n, m;
    static int[][] g;

    public static void main(String[] args) throws IOException {
        String[] s = bf.readLine().split(" ");
        n = Integer.parseInt(s[0]);
        m = Integer.parseInt(s[1]);
        g = new int[n + 1][m + 1];
        for (int i = 1; i <= n * m; i++) {
            char[] c = bf.readLine().toCharArray();
            int row = 1, col = 1;
            for (int j = 0; j < c.length; j++) {
                int index = c[j] - '1';
                if (index == -1) {
                    if (g[row][col] == 0) {
                        g[row][col] = i;
                    }
                    break;
                }
                if (row + dx[index] < 1 || row + dx[index] > n || col + dy[index] < 1 || col + dy[index] > m) continue;
                row += dx[index];
                col += dy[index];
            }
        }

        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                out.print(g[i][j]);
                out.flush();
                if(j < m){
                    out.print(" ");
                    out.flush();
                }
            }
                out.println();
                out.flush();
        }
        out.close();

    }
}
